//
//  WJTutorialSignPageViewController.swift
//  PDFSign
//
//  Created by 李永彬 on 2025/10/21.
//

import UIKit
import Lottie

class WJTutorialSignPageViewController: WJTutorialPageViewController {
    
    lazy var animationView: LottieAnimationView = {
        let animationView = LottieAnimationView(name: "animation2")
        animationView.contentMode = .scaleAspectFit
        animationView.loopMode = .loop
        animationView.animationSpeed = 1.0
        animationView.play()
        return animationView
    }()
    
    private lazy var drawView: WJPDFSignatureDrawView = {
        let view = WJPDFSignatureDrawView()
        view.layer.cornerRadius = 12
        view.clipsToBounds = true
        view.layer.borderColor = UIColor(hex: "#121212", alpha: 0.05).cgColor
        view.layer.borderWidth = 1
        view.tapDrawViewClosure = { [weak self] in
            guard let self = self else { return }
            tipsIcon.isHidden = true
        }
        return view
    }()
    
    private lazy var tipsIcon: UIImageView = {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFit
    
        imgView.image = UIImage(named: "gesture_tips")
        return imgView
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        commonInitSubViews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        // 视图消失时停止播放以节省资源
        animationView.stop()
    }
    
    func commonInitSubViews() {
        view.addSubview(animationView)
        animationView.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide).offset(30)
            make.leading.trailing.equalToSuperview().inset(16)
            make.height.equalTo(200)
        }
        
        view.addSubview(drawView)
        drawView.snp.makeConstraints { make in
            make.top.equalTo(animationView.snp.bottom).offset(20)
            make.leading.trailing.equalToSuperview().inset(16)
            make.bottom.equalToSuperview()
        }
        
        view.addSubview(tipsIcon)
        tipsIcon.snp.makeConstraints { make in
            make.center.equalTo(drawView)
        }
    }
}
